﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Matrix.Common.DBUtility;
using Matrix.MaKaYunShang.Model;

namespace Matrix.MaKaYunShang.DAL
{
	public partial class ShopMoneyChangeRecordDAL : BaseDAL<ShopMoneyChangeRecordDAL>
	{
        #region 默认方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ShopMoneyChangeRecord model)
        {
            var strSql = new StringBuilder();
            strSql.Append("insert into ShopMoneyChangeRecord(");
            strSql.Append("MxProjectInfoId,BeforeMoney,AfterMoney,ChangeSource,ChangeSerialNumber,ChangeMoney,OperaOpenId,OperaUserId,OperaSource,OperaResult,OutActivityCode,OrderId,AddTime,IsDelete,ShopId,ShareShopId");
            strSql.Append(") values (");
            strSql.Append("@MxProjectInfoId,@BeforeMoney,@AfterMoney,@ChangeSource,@ChangeSerialNumber,@ChangeMoney,@OperaOpenId,@OperaUserId,@OperaSource,@OperaResult,@OutActivityCode,@OrderId,@AddTime,@IsDelete,@ShopId,@ShareShopId");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
			            new SqlParameter("@MxProjectInfoId", SqlDbType.Int,4) ,            
                        new SqlParameter("@BeforeMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@AfterMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@ChangeSource", SqlDbType.Int,4) ,            
                        new SqlParameter("@ChangeSerialNumber", SqlDbType.NVarChar,32) ,            
                        new SqlParameter("@ChangeMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@OperaOpenId", SqlDbType.NVarChar,64) ,            
                        new SqlParameter("@OperaUserId", SqlDbType.Int,4) ,            
                        new SqlParameter("@OperaSource", SqlDbType.Int,4) ,            
                        new SqlParameter("@OperaResult", SqlDbType.Int,4) ,            
                        new SqlParameter("@OutActivityCode", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@OrderId", SqlDbType.Int,4) ,            
                        new SqlParameter("@AddTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@IsDelete", SqlDbType.Bit,1) ,            
                        new SqlParameter("@ShopId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ShareShopId", SqlDbType.Int,4)             
              
            };

            parameters[0].Value = model.MxProjectInfoId;
            parameters[1].Value = model.BeforeMoney;
            parameters[2].Value = model.AfterMoney;
            parameters[3].Value = model.ChangeSource;
            parameters[4].Value = model.ChangeSerialNumber;
            parameters[5].Value = model.ChangeMoney;
            parameters[6].Value = model.OperaOpenId;
            parameters[7].Value = model.OperaUserId;
            parameters[8].Value = model.OperaSource;
            parameters[9].Value = model.OperaResult;
            parameters[10].Value = model.OutActivityCode;
            parameters[11].Value = model.OrderId;
            parameters[12].Value = model.AddTime;
            parameters[13].Value = model.IsDelete;
            parameters[14].Value = model.ShopId;
            parameters[15].Value = model.ShareShopId; var obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            return obj == null ? 0 : Convert.ToInt32(obj);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ShopMoneyChangeRecord model)
        {
            var strSql = new StringBuilder();
            strSql.Append("update ShopMoneyChangeRecord set ");

            strSql.Append(" MxProjectInfoId = @MxProjectInfoId , ");
            strSql.Append(" BeforeMoney = @BeforeMoney , ");
            strSql.Append(" AfterMoney = @AfterMoney , ");
            strSql.Append(" ChangeSource = @ChangeSource , ");
            strSql.Append(" ChangeSerialNumber = @ChangeSerialNumber , ");
            strSql.Append(" ChangeMoney = @ChangeMoney , ");
            strSql.Append(" OperaOpenId = @OperaOpenId , ");
            strSql.Append(" OperaUserId = @OperaUserId , ");
            strSql.Append(" OperaSource = @OperaSource , ");
            strSql.Append(" OperaResult = @OperaResult , ");
            strSql.Append(" OutActivityCode = @OutActivityCode , ");
            strSql.Append(" OrderId = @OrderId , ");
            strSql.Append(" AddTime = @AddTime , ");
            strSql.Append(" IsDelete = @IsDelete , ");
            strSql.Append(" ShopId = @ShopId , ");
            strSql.Append(" ShareShopId = @ShareShopId  ");
            strSql.Append(" where Id=@Id ");

            SqlParameter[] parameters = {
			            new SqlParameter("@Id", SqlDbType.Int,4) ,            
                        new SqlParameter("@MxProjectInfoId", SqlDbType.Int,4) ,            
                        new SqlParameter("@BeforeMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@AfterMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@ChangeSource", SqlDbType.Int,4) ,            
                        new SqlParameter("@ChangeSerialNumber", SqlDbType.NVarChar,32) ,            
                        new SqlParameter("@ChangeMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@OperaOpenId", SqlDbType.NVarChar,64) ,            
                        new SqlParameter("@OperaUserId", SqlDbType.Int,4) ,            
                        new SqlParameter("@OperaSource", SqlDbType.Int,4) ,            
                        new SqlParameter("@OperaResult", SqlDbType.Int,4) ,            
                        new SqlParameter("@OutActivityCode", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@OrderId", SqlDbType.Int,4) ,            
                        new SqlParameter("@AddTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@IsDelete", SqlDbType.Bit,1) ,            
                        new SqlParameter("@ShopId", SqlDbType.Int,4) ,            
                        new SqlParameter("@ShareShopId", SqlDbType.Int,4)             
              
            };

            parameters[0].Value = model.Id;
            parameters[1].Value = model.MxProjectInfoId;
            parameters[2].Value = model.BeforeMoney;
            parameters[3].Value = model.AfterMoney;
            parameters[4].Value = model.ChangeSource;
            parameters[5].Value = model.ChangeSerialNumber;
            parameters[6].Value = model.ChangeMoney;
            parameters[7].Value = model.OperaOpenId;
            parameters[8].Value = model.OperaUserId;
            parameters[9].Value = model.OperaSource;
            parameters[10].Value = model.OperaResult;
            parameters[11].Value = model.OutActivityCode;
            parameters[12].Value = model.OrderId;
            parameters[13].Value = model.AddTime;
            parameters[14].Value = model.IsDelete;
            parameters[15].Value = model.ShopId;
            parameters[16].Value = model.ShareShopId; return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {
            var strSql = new StringBuilder();
            strSql.Append("update ShopMoneyChangeRecord set IsDelete=1 ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
        }

        /// <summary>
        /// 批量删除一批数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            var strSql = new StringBuilder();
            strSql.Append("update ShopMoneyChangeRecord set IsDelete=1 ");
            strSql.Append(" where Id in (" + Idlist + ")  ");
            return DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataSet GetModel(int Id)
        {
            var strSql = new StringBuilder();
            strSql.Append("select Id, MxProjectInfoId, BeforeMoney, AfterMoney, ChangeSource, ChangeSerialNumber, ChangeMoney, OperaOpenId, OperaUserId, OperaSource, OperaResult, OutActivityCode, OrderId, AddTime, IsDelete, ShopId, ShareShopId  ");
            strSql.Append("  from ShopMoneyChangeRecord ");
            strSql.Append(" where Id=@Id  and IsDelete=0");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            var ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds.Tables[0].Rows.Count > 0 ? ds : null;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            var strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM ShopMoneyChangeRecord where IsDelete=0 ");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" and " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        #endregion

        #region 扩展方法
        #endregion
	}
}
